package com.lad.transactional_propagation.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Component;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

/**
 * @author luheng
 * @create 2020-08-10 23:40
 */
@Component
public class TransactionConfig {
    @Autowired
    private DataSourceTransactionManager dataSourceTransactionManager;


    public TransactionStatus begin() {
        return dataSourceTransactionManager.getTransaction(new DefaultTransactionDefinition());
    }

    public void commit(TransactionStatus status) {
        dataSourceTransactionManager.commit(status);
    }

    public void rollback(TransactionStatus status) {
        dataSourceTransactionManager.rollback(status);
    }
}
